﻿/*!
	@file
	@author		Albert Semenov
	@date		01/2009
*/
#include "Precompiled.h"
#include "EditPanel.h"

#include <Windows.h>
#include "MyGUI_InputManager.h"
#include "MyGUI_Types.h"

using namespace MyGUI;

namespace demo
{

	EditPanel::EditPanel()
	{
		initialiseByAttributes(this);

		mEdit->getClientWidget()->eventMouseMove += newDelegate(this, &EditPanel::OnMouseMove);
	}

	void EditPanel::setColourSelected(const MyGUI::Colour& _colour)
	{
		mEdit->setTextSelectionColour(_colour);
	}

	void EditPanel::OnMouseMove( MyGUI::Widget* widget, int x, int y )
	{
		UString hightlightText = L"text";
		size_t startIdx = mEdit->getCaption().find(hightlightText);
		size_t endIdx = startIdx + hightlightText.length() - 1;

		IntPoint pos = InputManager::getInstance().getMousePosition();
		size_t text_pos = mEdit->getClientWidget()->getSubWidgetText()->getCursorPosition(IntPoint(x, y));

		if (text_pos>= startIdx && text_pos <= endIdx)
		{
			mEdit->setTextColour(Colour(1.0f, 0, 0));
		}
		else
		{
			mEdit->setTextColour(Colour(0.0f, 0.0f, 0.0f));
		}

		char buff[256];
		sprintf(buff, "cursor pos: %d", text_pos);
		OutputDebugString(buff);
	}

} // namespace demo
